﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ST.Torch.WebApi.Core.Entities.System
{

    public class SYSRole : SoftDeleteBaseEntity, IEntityTypeBuilder<SYSRole>
    {
        /// <summary>
		/// 角色名称
		/// </summary>
		[MaxLength(100)]
        public string Name { get; set; }
        /// <summary>
		/// 标识
		/// </summary>
		[MaxLength(100)]
        public string RoleCode { get; set; }
        //public virtual List<SYSRoleMenu> RoleMenus { get; set; }
        public virtual List<SYSMenu> Menus { get; set; }
        public virtual List<SYSUser> Users { get; set; }

        
        public void Configure(EntityTypeBuilder<SYSRole> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            entityBuilder.HasKey(u => u.Id);
            entityBuilder.HasQueryFilter(u => !u.IsDeleted);

            //多对对
            entityBuilder.HasMany(u => u.Menus).WithMany(u=>u.Roles).UsingEntity(e => e.ToTable("SYSRoleMenu")); 
        }
    }
}
